#include<sys/types.h>
#include<sys/stat.h>
#include<iostream>
#include<cstring>
#include<unistd.h>
#include<cstdlib>
#include<fcntl.h>
#include<string>

int main()
{
  //打开信道
  
  int fd = open("pfifo", O_WRONLY);
  
  if (fd < 0)
  {
    perror("client: namepipes open error");
    exit(-4);
  }


  //开始通信
  

  std::string s = "Hello namepipes!!!";
  while (true)
  {
    std::cout << "server:  ";
    std::getline(std::cin, s);
    if (s.size() == 0)
    {
      close(fd);
      break;
    }
    int n = write(fd, s.c_str(), s.size());
    if (n < 0)
    {
      perror("client: write error");
      exit(-5);
    }
  }


  return 0;
}
